import {
    Message
} from 'element-ui';
export default {
    state: {
        cartList: []
    },
    mutations: {
        setCartList(state, count) {
            let status = state.cartList.findIndex(item => item.name == count.name);
            if (status === -1) {
                count.count++;
                state.cartList.push(count)
            } else {
                state.cartList[status].count++
            }
        },
        addCartCount(state, index) {
            state.cartList[index].count++
        },
        subCartCount(state, index) {
            let count = state.cartList[index].count;
            if (count > 1) {
                state.cartList[index].count--;
            } else {
                Message.error('不能在减了，这已经是我的底线了！')
            }
        },
        delShopCart(state, index) {
            state.cartList.splice(index, 1)
        },
        totalPrice(state, rows) {
            state.cartList.push(rows);
        }
    },
    actions: {},
    modules: {}
}